package com.vue.controller;

import com.vue.bean.R;
import com.vue.entity.es.EsUserDto;
import com.vue.entity.es.EsUserEntity;
import com.vue.service.EsIdxPersonService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * ES搜索人员信息
 *
 * @author: wrj
 * @since: 2025/1/6 16:09
 * @description:
 */
@Slf4j
@EnableScheduling
@RestController
@AllArgsConstructor
@RequestMapping("/person")
public class EsIdxPersonController {

    private final EsIdxPersonService service;

    /**
     * 查询用户信息
     * @param dto null
     * @return R<List<EsIdxPersonEntity>>
     * @author wrj
     * @since 2025/1/6 下午4:10
     */
    @PostMapping("/searchUser")
    public R<List<EsUserEntity>> searchUser(@RequestBody EsUserDto dto) throws IOException {
        List<EsUserEntity> res = service.searchUser(dto);
        return R.data(res);
    }

    /**
     * 定时将人员信息添加进ES
     * 测试5分钟拉取一次最新用户数据
     * @return R
     * @author wrj
     * @since 2025/1/6 下午4:10
     */
//    @Scheduled(cron = "0 0/5 * * * ?")
    @GetMapping("/savePersonData")
    public R savePersonData(Integer pageNum, Integer pageSize) throws IOException {
        service.savePersonData(pageNum, pageSize);
        return R.status(true);
    }

//    @Scheduled(cron = "0 0/3 * * * ?")
    @GetMapping("/saveOnePersonData")
    public R saveOnePersonData() throws IOException {
        EsUserEntity esUserEntity = new EsUserEntity();
        service.saveOnePersonData(esUserEntity);
        return R.status(true);
    }

}

